package com.bidevalution.business.impl;

import com.bidevalution.business.service.FileCompareService;
import com.bidevalution.dao.entity.FileCompareResult;
import com.bidevalution.dao.mapper.FileCompareResultMapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.NumberFormat;
import java.util.List;
import java.util.Map;

/**
 * Created by glodon on 2019-08-27.
 */
@Service
public class FileCompareServiceImpl implements FileCompareService {

    @Autowired
    private FileCompareResultMapper fileCompareResultMapper;
    /**
     * 获取企业文件相似度对比结果
     * @param sectionId
     * @param enterpriseId
     * @param evalContentType
     * @param similar
     * @return
     * @throws Exception
     */
    @Override
    public List<FileCompareResult> getSimilarEnterprise(String sectionId, String enterpriseId, String evalContentType, String similar) throws Exception {
        float s = 0;
        if(StringUtils.isNotBlank(similar)){
            NumberFormat nf=NumberFormat.getPercentInstance();
            Number number = nf.parse(similar);
            s = number.floatValue();
        }
        return fileCompareResultMapper.getSimilarEnterprise(sectionId, enterpriseId, evalContentType, s);
    }

    @Override
    public List<Map<String, String>> getCompareEnterprise(String sectionId, String methodId) throws Exception {
        return fileCompareResultMapper.getCompareEnterprise(sectionId, methodId);
    }

    @Override
    public List<Map<String, String>> getCompareSections() throws Exception {
        return fileCompareResultMapper.getCompareSections();
    }

    /**
     * 保存相似度对比结果
     * @param fileCompareResult
     * @return
     * @throws Exception
     */
    @Override
    public int saveSimilarEnterprise(FileCompareResult fileCompareResult) throws Exception {
        return fileCompareResultMapper.insert(fileCompareResult);
    }

    /**
     * 根据标段id和评审内容id获取技术标文件
     * @param sectionId
     * @param methodId
     * @param enterpriseId
     * @return
     * @throws Exception
     */
    @Override
    public String getTechnologyPdf(String sectionId, String methodId, String enterpriseId) throws Exception {
        return fileCompareResultMapper.getTechnologyPdf(sectionId,methodId, enterpriseId);
    }

    @Override
    public List<Map<String, String>> getEvalContentList(String sectionId) throws Exception {
        return fileCompareResultMapper.getEvalContentList(sectionId);
    }
}
